#include "DigiJoystick.h"
#include "makros.h"
#include "debug.h"
#include "RCReceive.h"

#define USE_TIMER_1
const byte PIN_RC = 2; 
RCReceive rcReceiver;
void setup() {
  rcReceiver.attach(PIN_RC);

  // put your setup code here, to run once:
}

void loop() {
  // Aktuellen RC-Wert lesen
  rcReceiver.poll();

  // Nullpunktsbestimmung ?
  if (rcReceiver.hasNP() && !rcReceiver.hasError()) {
    doWork();
  } else if (rcReceiver.hasError()) {
    // Fehlerbehandlung failsafe oder sowas...
  }
}

void doWork() {
  byte value = rcReceiver.getValue();
  DigiJoystick.setX((byte) (millis() / 100)); // scroll X left to right repeatedly
  DigiJoystick.setY((byte) (millis() / 100));
  DigiJoystick.setXROT((byte) (millis() / 100));
  DigiJoystick.setYROT((byte) (millis() / 100));
  DigiJoystick.setZROT((byte) (millis() / 100));
  DigiJoystick.setSLIDER((byte) (millis() / 100) );
  DigiJoystick.setButtons('1', '0');
  // put your main code here, to run repeatedly: 
  DigiJoystick.delay(50); // wait 50 milliseconds
}
